package Exercise;

import java.util.Arrays;

/**
 * Description：
 * Author: zhangc
 * Date：2017/8/6 16:33
 */
public class Flip {

    public static int[][] flipChess(int[][] A, int[][] f) {
        if (A == null || f == null || A.length != 4 || A[ 0 ].length != 4 || f[ 0 ].length != 2)
            return null;
        for (int i = 0; i < f.length; i++) {
            int row = f[ i ][ 0 ], col = f[ i ][ 1 ];
            if (row <= 0 || row > A.length || col <= 0 || col > A.length)
                return null;
            if (row > 1)
                A[ row - 2 ][ col - 1 ] = A[ row - 2 ][ col - 1 ] == 0 ? 1 : 0;
            if (row < A.length)
                A[ row ][ col - 1 ] = A[ row ][ col - 1 ] == 0 ? 1 : 0;
            if (col > 1)
                A[ row - 1 ][ col - 2 ] = A[ row - 1 ][ col - 2 ] == 0 ? 1 : 0;
            if (col < A.length)
                A[ row - 1 ][ col ] = A[ row - 1 ][ col ] == 0 ? 1 : 0;
        }
        return A;
    }


    public static void main(String[] args) {
        int[][] A = {{0, 0, 1, 1}, {1, 0, 1,0}, {0, 1, 1, 0}, {0, 0, 1, 0}};
        int[][] B = {{2, 2}, {3, 3}, {4, 4}};
        int[][] ints = flipChess(A, B);
        System.out.println();
    }

}
